/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MyClass;

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.TiledLayer;

/**
 *
 * @author HuuTai_it
 */
public class Islands extends TiledLayer {
    
    public Islands (GameManagement gameMng, Image image) throws Exception {
        
        super(10, 10, image, 24, 24); 
        
        int numIslands = Math.abs(gameMng.r.nextInt() % 4);
        if(gameMng.control.difficulties == 1)
            numIslands += 6;  
        else
            numIslands += 4; 
        
        for(int i = 0; i < 10; i++)
            for(int j = 0; j < 10; j++)
                setCell(j, i, 0);
        
        for(int i = 0; i < numIslands;)
        {            
            int x, y;
            do {
                
                x = Math.abs(gameMng.r.nextInt() % 10);
                y = Math.abs(gameMng.r.nextInt() % 10);
            }while(gameMng.element[x][y] != 0);
            
            setCell(x, y, Math.abs(gameMng.r.nextInt() % 2) + 1);
            gameMng.element[x][y] = 2;
            i++;
        }
    }   
}
